package com.ada;

import com.ada.component.ConsumerComponent;
import com.ada.filter.MethodUtil;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class DubboConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        //获取消费者组件
        ConsumerComponent consumerComponent = context.getBean(ConsumerComponent.class);
        //System.in.read();
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                MethodUtil.show();
            }
        }, 5, 5, TimeUnit.SECONDS);
        while (true) {
            try {
                String world = consumerComponent.sayA("world");
                //System.out.println(world);
                String world2 = consumerComponent.sayB("world");
                //System.out.println(world2);
                String world3 = consumerComponent.sayC("world");
                //System.out.println(world3);

                Thread.sleep(20);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

    @Configuration
    @EnableDubbo
    @PropertySource("classpath:/dubbo-provider.properties")
    @ComponentScan(basePackages = "com.ada.component")
    static class ConsumerConfiguration {

    }
}
